﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using EnvDTE;
using VSIXUtilities.Helpers.Extensions;

namespace CodeDocumentationSynchronizer.CodDocSync.GUI
{
    public partial class FormFileCodeModelBrowser : Form
    {
        public FormFileCodeModelBrowser(FileCodeModel FileCodeModelInstance)
        {
            InitializeComponent();
            Populate(FileCodeModelInstance);
        }


        private void Populate(FileCodeModel FileCodeModelToSearchIn)
        {
            foreach (CodeElement CodeElementInstance in FileCodeModelToSearchIn.CodeElements)
            {
                Populate(CodeElementInstance, null);
            }
        }

        private void Populate(CodeElement CodeElementInstance, TreeNode Related)
        {
            TreeNode tn = new TreeNode(CodeElementInstance.GetFriendlyName())
            {
                Tag = CodeElementInstance
            };
            if (Related == null)
            {
                treeView1.Nodes.Add(tn);
            }
            else
            {
                Related.Nodes.Add(tn);
            }
            foreach (CodeElement CodeElementChild in CodeElementInstance.Children)
            {
                Populate(CodeElementChild, tn);
            }
        }

        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            propertyGrid1.SelectedObject = e.Node.Tag;
        }
    }
}
